package com.client.rule.triple;

import java.util.Map;

import com.google.gwt.user.client.Window;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.Node;
import com.shared.rule.TypeDataRule;
import com.shared.rule.TypeOperator;

public class UiSimpleTriple extends UiTriple{
	
	private String label1;	
	private String label2;	
	private TypeOperator typeOperator;
	
	public UiSimpleTriple() {
		super();		
	}
	
		
	public UiSimpleTriple(String label1,String label2,TypeOperator typeOperator) {
		super();	
		this.label1 =label1;
		this.label2=label2;		
		this.typeOperator=typeOperator;
	}	
	
	@Override
	public void generateFromXML(Node xmlNode) {			
		Element tripleElement = (Element) xmlNode;		
		label1 = tripleElement.getAttribute("label1");
		label2 = tripleElement.getAttribute("label2");		
		typeOperator = TypeOperator.getType(tripleElement.getAttribute("operator"));		
	}
	
	
	
	@Override
	public boolean isComplex() {		
		return false;
	}

	

	@Override
	public String toXml(Map<String,TypeDataRule> mapData) {		
		return "<Triple type=\""+typeOperator.getTypeData().toString()+"Triple"+"\" label1=\""+label1+"\" label2=\""+label2+"\" operator=\""+typeOperator.toString()+"\" />";				
	}



	/**
	 * @param label1 the label1 to set
	 */
	public void setLabel1(String label1) {
		this.label1 = label1;
	}



	/**
	 * @return the label1
	 */
	public String getLabel1() {
		return label1;
	}



	/**
	 * @param label2 the label2 to set
	 */
	public void setLabel2(String label2) {
		this.label2 = label2;
	}



	/**
	 * @return the label2
	 */
	public String getLabel2() {
		return label2;
	}



	@Override
	public void getUsedDataXml(Map<String, String> usedData,Map<String,TypeDataRule> mapData) {	
			if(mapData.get(label1)==null){
				usedData.put(label1, "<data label=\""+label1+"\" type=\""+typeOperator.getTypeData().toString()+"\" value=\""+label1+"\" />");
			}else{
				usedData.put(label1, "<data label=\""+label1+"\" type=\""+typeOperator.getTypeData().toString()+"\" />");
			}
			if(mapData.get(label2)==null){
				usedData.put(label2, "<data label=\""+label2+"\" type=\""+typeOperator.getTypeData().toString()+"\" value=\""+label2+"\" />");
			}else{
				usedData.put(label2, "<data label=\""+label2+"\" type=\""+typeOperator.getTypeData().toString()+"\" />");
			}
	}

	public TypeOperator getTypeOperator() {
		return typeOperator;
	}
	
}
